package honeypot.ypzxtgl.action;

import java.io.FileWriter;
import java.io.IOException;

import honeypot.ypzxtgl.pojo.Dzmn;
import cm.util.action.info.GenericInfoActionSupport;
import cm.util.exception.MessageException;

public class DzmnInfoAction extends GenericInfoActionSupport<Dzmn> {
	private String name;
	private String ip;
	private String port;
	private String service;
	private String os;
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getPort() {
		return port;
	}

	public void setPort(String port) {
		this.port = port;
	}

	public String getOs() {
		return os;
	}

	public void setOs(String os) {
		this.os = os;
	}

	public DzmnInfoAction() {
		super( Dzmn.class);
	}

	@Override
	public String update() throws MessageException {

		 FileWriter fileWriter;
		try {
			fileWriter = new FileWriter("/root/honeyd/honeyd-1.5C/honeyd.conf",true);
			 String [] a=new String[]{"\r\n"+"### "+entity.getOs()+"\r\n"+"create "+entity.getName()+"\r\n"
					 +"set "+entity.getName()+" personality "+"\""+entity.getOs()+"\""+"\r\n"
					 +"set "+entity.getName()+" default tcp action open"+"\r\n"
					 +"set "+entity.getName()+" default udp action block"+"\r\n"
					 +"set "+entity.getName()+" default icmp action block"+"\r\n"
					 +"add "+entity.getName()+" tcp port "+entity.getPort()+" open"+"\r\n"
					 +"add "+entity.getName()+" tcp port 137 open"+"\r\n"
					 +"add "+entity.getName()+" udp port 137 open"+"\r\n"
					 +"add "+entity.getName()+" udp port 135 open"+"\r\n"
					 +"bind "+entity.getIp()+" "+entity.getName()+"\r\n"
			 };
			   for (int i = 0; i < a.length; i++) {
			    fileWriter.write(String.valueOf(a[i]));
			     }
			    fileWriter.flush();
				fileWriter.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		  
		   
		
		
		return super.update();
	}
	
}
